﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.UI.HtmlControls;

using AjaxControlToolkit;
using BizElements.Core;
using BizElements.BusinessLayer;

namespace BizElements.Web
{
    /// <summary>Represents a parent binding to <see cref="IBoundLookupControl"/> control.</summary>
    /// <typeparam name="TParentTable">Metadata class for table that contains parent records.</typeparam>
    /// <typeparam name="TSearchEngineBuilder">Search class</typeparam>
    public sealed class ParentLookupBinding<TParentTable, TSearchEngineBuilder> : ParentBindingBase<TParentTable>, IParentBinding
        where TParentTable : IDbTable, new()
        where TSearchEngineBuilder : ISearchEngineBuilder, new()
    {
        #region CTor.

        /// <summary>Initializes a new instance of ParentLookupBinding class.</summary>
        /// <param name="parentEntityDescriptor">Parent entity descriptor. Additional features are available for composite entities.</param>
        /// <param name="foreignKeyField">FK field.</param>
        /// <param name="boundLookupControl">Lookup control bound to FK field.</param>
        /// <param name="searchProviderBuilder">Search provider builder.</param>
        /// <param name="parentFormUrl">Parent form URL. Required if create new parent and open parent details are used.</param>
        /// <param name="openParentDetailsControl">Optional open parent details control.</param>
        /// <param name="createNewParentControl">Optional create new parent control.</param>
        public ParentLookupBinding(IDataObjectDescriptor parentEntityDescriptor, IDbColumn foreignKeyField, IBoundLookupControl boundLookupControl, SearchProviderBuilder searchProviderBuilder, string parentFormUrl, Control openParentDetailsControl, Control createNewParentControl)
            : base(parentEntityDescriptor, foreignKeyField, boundLookupControl, searchProviderBuilder, parentFormUrl, openParentDetailsControl, createNewParentControl, true)
        {
        }

        #endregion

        #region NewSearchEngineBuilder.

        /// <summary>Creates a new instance of search engine builder class.</summary>
        /// <returns>An ISearchEngineBuilder class or null if FK is bound to a list control.</returns>
        public override ISearchEngineBuilder NewSearchEngineBuilder()
        {
            return new TSearchEngineBuilder();
        }

        #endregion
    }
}
